package com.nsharmon.model.transformer;

import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

import com.nsharmon.dao.entity.Axiom;
import com.nsharmon.dao.entity.ConditionAxiom;

public class ConditionTransformer implements Transformer {

	@Override
	public boolean transformBegin() {
		return true;
	}
	
	@Override
	public Set<Axiom> transform(Set<Axiom> axioms) {
		Set<Axiom> generatedAxioms = new LinkedHashSet<Axiom>();
		
		// Search for extra relationships
		Iterator<Axiom> it = axioms.iterator();
		while(it.hasNext()) {
			Axiom axiom = it.next();
			if(axiom instanceof ConditionAxiom) {
				ConditionAxiom ca = (ConditionAxiom)axiom;
				if(!axioms.contains(ca.getAxiom()) && ca.getCondition().evaluate(axioms)) {
					generatedAxioms.add(ca.getAxiom());
				}
			}
		}
		return generatedAxioms;
	}


	@Override
	public Set<Axiom> transformEnd( Set<Axiom> axioms ) {
		return null;
	}
}
